package com.cll.prototype.stream.service.impl;

import com.cll.prototype.stream.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;

/**
 * 描述信息:
 *
 * 注解@EnableBinding中Source.class里面就是对输出通道的定义（这是Spring Cloud Stream内置的通道封装）
 * @author CLL
 * @version 1.0
 * @date 2020/11/10 9:37
 */
@EnableBinding(Source.class)
public class MessageProviderImpl implements IMessageProvider {

    @Autowired
    private Source source;

    @Override
    public void sendMessage(String content) {
        /*
        向mq中发送消息（并不是直接操作mq，应该操作的是spring cloud stream）
        使用通道向外发出消息(指的是Source里面的output通道)
         */
        source.output().send(MessageBuilder.withPayload(content).build());
    }
}